package com.punai.costData.controller;

import cn.hutool.core.util.ObjectUtil;
import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.common.core.page.TableDataInfo;
import com.punai.externalccb.bo.EcoCbfeeitemBo;
import com.punai.externalccb.constants.CCBConstants;
import com.punai.externalccb.domain.EcoCbfeeitem;
import com.punai.externalccb.domain.EcoCbsummary;
import com.punai.externalccb.service.IEcoCbfeeitemService;
import com.punai.prodatalibrary.domain.LibProject;
import com.punai.prodatalibrary.domain.LibProjectInfo;
import com.punai.prodatalibrary.domain.bo.GlobalProInfoBo;
import com.punai.prodatalibrary.service.ILibProjectInfoService;
import com.punai.prodatalibrary.service.ILibProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.punai.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/costData/projectCostDataPre")
public class ProjectCostDataPreController extends BaseController {
    @Autowired
    private ILibProjectService libProjectService;
    @Autowired
    private ILibProjectInfoService libProjectInfoService;
    @Autowired
    private IEcoCbfeeitemService ecoCbfeeitemService;
    /**
     * 查询项目主表列表
     */
    @PreAuthorize("@ss.hasPermi('costData:projectCostDataPre:list')")
    @GetMapping("/list")
    public TableDataInfo list(GlobalProInfoBo bo)
    {
        startPage();
        return libProjectService.selectProjectInfoList(bo);
    }

    @PreAuthorize("@ss.hasPermi('costData:projectCostDataPre:query')")
    @PostMapping("/listTabData")
    public TableDataInfo listTabData(EcoCbfeeitem cbfeeitem)
    {
        LibProjectInfo info = libProjectInfoService.selectLibProjectInfoById(cbfeeitem.getProId());
        if (ObjectUtil.isNotEmpty(info)) cbfeeitem.setProId(info.getProId());
        List<EcoCbfeeitemBo> ecoCbfeeitems = ecoCbfeeitemService.selectEcoCbfeeitemList(cbfeeitem);
        return getDataTable(ecoCbfeeitems);
    }

    @PreAuthorize("@ss.hasPermi('costData:projectCostDataPre:query')")
    @PostMapping("/jsxmxListTabData")
    public TableDataInfo jsxmxListTabData(EcoCbfeeitem cbfeeitem)
    {
        LibProjectInfo info = libProjectInfoService.selectLibProjectInfoById(cbfeeitem.getProId());
        if (ObjectUtil.isNotEmpty(info)) cbfeeitem.setProId(info.getProId());
        List<EcoCbfeeitemBo> ecoCbfeeitems = ecoCbfeeitemService.selectJsxmxListTabData(cbfeeitem);
        return getDataTable(ecoCbfeeitems);
    }

    @PreAuthorize("@ss.hasPermi('costData:projectCostDataPre:query')")
    @PostMapping("/cbhzListTabData")
    public TableDataInfo cbhzListTabData(EcoCbfeeitem cbfeeitem)
    {
        LibProjectInfo info = libProjectInfoService.selectLibProjectInfoById(cbfeeitem.getProId());
        if (ObjectUtil.isNotEmpty(info)) cbfeeitem.setProId(info.getProId());
        List<EcoCbsummary> ecoCbsummarys = ecoCbfeeitemService.selectCbhzListTabData(cbfeeitem);
        return getDataTable(ecoCbsummarys);
    }
}
